package com.friday.listener;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class OnlineUserListener implements HttpSessionListener{

	@Override
	public void sessionCreated(HttpSessionEvent se) {
		
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent se) {
		HttpSession session = se.getSession();
		ServletContext application = session.getServletContext();
		
		String userName = (String)session.getAttribute("account");
		
		List onlineUserList = (List)application.getAttribute("OnlineUserList");
		
		if(onlineUserList.contains(userName)) {
			onlineUserList.remove(userName);
		}
	}
}